package com.ssvendas.converter;

import javax.ejb.EJB;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

import com.ssvendas.fachadas.remote.QueryMFFRemote;
import com.ssvendas.modelo.Filial;

@javax.persistence.Converter
public class FilialConverter implements Converter{

	@EJB
	private QueryMFFRemote queryMFF;
	
	@Override
	public Object getAsObject(FacesContext context, UIComponent component,
			String value) {
		Filial filial = queryMFF.getFilialNome(value);
		return filial;
	}

	@Override
	public String getAsString(FacesContext context, UIComponent component,
			Object value) {
		if(value==null)return "";
		Filial f = (Filial) value;
		return f.getNome();
	}

}
